package com.xiaoxi.observermode.generator;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.observermode.generator
 * @ClassName RandomNumberGenerator
 * @Description TODO
 * @Date 2023/3/27 15:51
 * @Version 1.0
 */
public class IncrementalNumberGenerator extends NumberGenerator {

    private Integer begin;
    private Integer end;
    private Integer step;
    private Integer currentNumber;

    public IncrementalNumberGenerator(Integer begin, Integer end, Integer step) {
        this.begin = begin;
        this.end = end;
        this.step = step;
    }

    @Override
    public Integer getNumber() {
        return currentNumber;
    }

    @Override
    public void execute() {
        for (int i = begin; i <= end; i += step) {
            currentNumber = i;
            notifyObservers();
        }
    }
}
